package mybatis.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageInfo;
import mybatis.entity.Game;
import mybatis.service.GamesService;
import mybatis.service.impl.GamesServiceImpl;

/**
 * Servlet implementation class GamesServlet
 */
@WebServlet("/games/*")
public class GamesServlet extends BaseServlet {
	public void findByPage(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("currentPage");
		GamesService service = applicationContext.getBean("gamesServiceImpl", GamesServiceImpl.class);
		List<Game> list = service.findNewGames(Integer.parseInt(currentPage));
		PageInfo<Game> page = new PageInfo(list);
		System.out.println(page);
		try {
			responseJson(response,page);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
